package com.cheyunkeji.er.adapter.auction;

import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.ImageView;
import android.widget.TextView;

import com.cheyun.netsalev3.R;
import com.cheyunkeji.er.adapter.MyBaseAdapter;
import com.cheyunkeji.er.bean.auction.SystemNotifyApplyType;

import java.util.ArrayList;

import butterknife.BindView;
import butterknife.ButterKnife;

/**
 * Created by Michael on 2017/2/16 15:45.
 */

public class SystemNotifyLvItemAdapter extends MyBaseAdapter {

    public SystemNotifyLvItemAdapter(ArrayList<SystemNotifyApplyType> dataList, Context context) {
        super(dataList, context);
    }

    @Override
    public View getView(int position, View convertView, ViewGroup parent) {

        final ViewHolder holder;
        if (convertView == null) {
            convertView = LayoutInflater.from(context).inflate(R.layout.er_system_notify_record_item, null);
            holder = new ViewHolder(convertView);
            convertView.setTag(holder);
        } else {
            holder = (ViewHolder) convertView.getTag();
        }

        SystemNotifyApplyType itemBean = (SystemNotifyApplyType) dataList.get(position);
        holder.tvNotifyType.setText(displayTextByType(itemBean.getType()));
        holder.tvContentDesc.setText(itemBean.getApplyResult());
        holder.tvTime.setText(itemBean.getApplyTime());
        return convertView;
    }

    private String displayTextByType(int type) {
        String defaultResult = "";
        switch (type) {
            case 1:
                defaultResult = context.getResources().getString(R.string.apply_success);
                break;
            case 2:
                defaultResult = context.getResources().getString(R.string.apply_refused);
                break;
            case 3:
                defaultResult = context.getResources().getString(R.string.apply_waitting);
                break;

            default:
                break;
        }
        return defaultResult;
    }


    static class ViewHolder {
        @BindView(R.id.tv_notify_type)
        TextView tvNotifyType;
        @BindView(R.id.tv_content_desc)
        TextView tvContentDesc;
        @BindView(R.id.iv_is_new_msg)
        ImageView ivIsNewMsg;
        @BindView(R.id.tv_time)
        TextView tvTime;

        ViewHolder(View view) {
            ButterKnife.bind(this, view);
        }
    }
}
